package cn.wolfcode.trip.admin.controller;


import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("images")
public class ImageController {

    @PostMapping
    public Map upload(MultipartFile upload ){
       HashMap<String, Object> map = new HashMap<>();
        //把图片传到指定的路径
        try {
            //String url = UploadUtil.upload(file, UploadUtil.Path + "/upload");
            String url = UploadUtil.uploadALiYun(upload);
            map.put("uploaded",1);
            map.put("url",url);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("uploaded",0);
            HashMap<String,String> tempMap = new HashMap<>();
            tempMap.put("message","上传失败");
            map.put("erro",tempMap);
        }
        return map;
    }

}
